from time import sleep
import pytest
from selenium import webdriver
from tests.utils import htmlUtils
import logging

# @pytest.fixture(scope="session", autouse=True)
@pytest.fixture(scope="function")
def login_module(config: dict, driver: webdriver, base_url: str):
    # 用户登录
    logging.info(f"开始用户登录")
    login(config["dwh"]["username"], config["dwh"]["password"], driver, base_url)
    
def login(username: str, password: str, driver: webdriver, base_url: str):
    # 登录系统的逻辑
    driver.get(base_url + "#/login")
    sleep(2)
    htmlUtils.getElementByXPath(driver, '//input[@type="text"]').send_keys(username)
    htmlUtils.getElementByXPath(driver, '//input[@type="password"]').send_keys(password)
    sleep(2)
    loginButton = htmlUtils.getElementByXPath(driver, '//button[@type = "button"]')
    loginButton.click()
    sleep(2)
    



